package com.j256.ormlite.android;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.j256.ormlite.android.compat.ApiCompatibility;
import com.j256.ormlite.android.compat.ApiCompatibility.CancellationHook;
import com.j256.ormlite.android.compat.ApiCompatibilityUtils;
import com.j256.ormlite.dao.ObjectCache;
import com.j256.ormlite.field.SqlType;
import com.j256.ormlite.logger.Logger;
import com.j256.ormlite.logger.LoggerFactory;
import com.j256.ormlite.misc.SqlExceptionUtil;
import com.j256.ormlite.stmt.StatementBuilder.StatementType;
import com.j256.ormlite.support.CompiledStatement;
import com.j256.ormlite.support.DatabaseResults;
import java.util.ArrayList;
import java.util.List;

public class AndroidCompiledStatement
  implements CompiledStatement
{
  private static final String[] NO_STRING_ARGS = new String[0];
  private static final ApiCompatibility apiCompatibility = ApiCompatibilityUtils.getCompatibility();
  private static Logger logger = LoggerFactory.getLogger(AndroidCompiledStatement.class);
  private List<Object> args;
  private final boolean cancelQueriesEnabled;
  private ApiCompatibility.CancellationHook cancellationHook;
  private Cursor cursor;
  private final SQLiteDatabase db;
  private Integer max;
  private final String sql;
  private final StatementBuilder.StatementType type;

  public AndroidCompiledStatement(String paramString, SQLiteDatabase paramSQLiteDatabase, StatementBuilder.StatementType paramStatementType, boolean paramBoolean)
  {
    this.sql = paramString;
    this.db = paramSQLiteDatabase;
    this.type = paramStatementType;
    this.cancelQueriesEnabled = paramBoolean;
  }

  // ERROR //
  static int execSql(SQLiteDatabase paramSQLiteDatabase, String paramString1, String paramString2, Object[] paramArrayOfObject)
    throws java.sql.SQLException
  {
    // Byte code:
    //   0: aload_0
    //   1: aload_2
    //   2: aload_3
    //   3: invokevirtual 75	android/database/sqlite/SQLiteDatabase:execSQL	(Ljava/lang/String;[Ljava/lang/Object;)V
    //   6: aconst_null
    //   7: astore 5
    //   9: aload_0
    //   10: ldc 77
    //   12: invokevirtual 81	android/database/sqlite/SQLiteDatabase:compileStatement	(Ljava/lang/String;)Landroid/database/sqlite/SQLiteStatement;
    //   15: astore 5
    //   17: aload 5
    //   19: invokevirtual 87	android/database/sqlite/SQLiteStatement:simpleQueryForLong	()J
    //   22: lstore 9
    //   24: lload 9
    //   26: l2i
    //   27: istore 8
    //   29: aload 5
    //   31: ifnull +8 -> 39
    //   34: aload 5
    //   36: invokevirtual 90	android/database/sqlite/SQLiteStatement:close	()V
    //   39: getstatic 39	com/j256/ormlite/android/AndroidCompiledStatement:logger	Lcom/j256/ormlite/logger/Logger;
    //   42: ldc 92
    //   44: aload_1
    //   45: iload 8
    //   47: invokestatic 98	java/lang/Integer:valueOf	(I)Ljava/lang/Integer;
    //   50: aload_2
    //   51: invokevirtual 104	com/j256/ormlite/logger/Logger:trace	(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
    //   54: iload 8
    //   56: ireturn
    //   57: astore 4
    //   59: new 106	java/lang/StringBuilder
    //   62: dup
    //   63: invokespecial 107	java/lang/StringBuilder:<init>	()V
    //   66: ldc 109
    //   68: invokevirtual 113	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   71: aload_1
    //   72: invokevirtual 113	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   75: ldc 115
    //   77: invokevirtual 113	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   80: aload_2
    //   81: invokevirtual 113	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   84: invokevirtual 119	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   87: aload 4
    //   89: invokestatic 125	com/j256/ormlite/misc/SqlExceptionUtil:create	(Ljava/lang/String;Ljava/lang/Throwable;)Ljava/sql/SQLException;
    //   92: athrow
    //   93: astore 7
    //   95: iconst_1
    //   96: istore 8
    //   98: aload 5
    //   100: ifnull -61 -> 39
    //   103: aload 5
    //   105: invokevirtual 90	android/database/sqlite/SQLiteStatement:close	()V
    //   108: goto -69 -> 39
    //   111: astore 6
    //   113: aload 5
    //   115: ifnull +8 -> 123
    //   118: aload 5
    //   120: invokevirtual 90	android/database/sqlite/SQLiteStatement:close	()V
    //   123: aload 6
    //   125: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   0	6	57	android/database/SQLException
    //   9	24	93	android/database/SQLException
    //   9	24	111	finally
  }

  private Object[] getArgArray()
  {
    if (this.args == null)
      return NO_STRING_ARGS;
    return this.args.toArray(new Object[this.args.size()]);
  }

  private String[] getStringArray()
  {
    if (this.args == null)
      return NO_STRING_ARGS;
    return (String[])this.args.toArray(new String[this.args.size()]);
  }

  private void isInPrep()
    throws java.sql.SQLException
  {
    if (this.cursor != null)
      throw new java.sql.SQLException("Query already run. Cannot add argument values.");
  }

  public void cancel()
  {
    if (this.cancellationHook != null)
      this.cancellationHook.cancel();
  }

  public void close()
    throws java.sql.SQLException
  {
    if (this.cursor != null);
    try
    {
      this.cursor.close();
      this.cancellationHook = null;
      return;
    }
    catch (android.database.SQLException localSQLException)
    {
      throw SqlExceptionUtil.create("Problems closing Android cursor", localSQLException);
    }
  }

  public void closeQuietly()
  {
    try
    {
      close();
      return;
    }
    catch (java.sql.SQLException localSQLException)
    {
    }
  }

  public int getColumnCount()
    throws java.sql.SQLException
  {
    return getCursor().getColumnCount();
  }

  public String getColumnName(int paramInt)
    throws java.sql.SQLException
  {
    return getCursor().getColumnName(paramInt);
  }

  public Cursor getCursor()
    throws java.sql.SQLException
  {
    Object localObject;
    if (this.cursor == null)
      localObject = null;
    try
    {
      Integer localInteger = this.max;
      localObject = null;
      if (localInteger == null);
      String str;
      for (localObject = this.sql; ; localObject = str)
      {
        if (this.cancelQueriesEnabled)
          this.cancellationHook = apiCompatibility.createCancellationHook();
        this.cursor = apiCompatibility.rawQuery(this.db, (String)localObject, getStringArray(), this.cancellationHook);
        this.cursor.moveToFirst();
        logger.trace("{}: started rawQuery cursor for: {}", this, localObject);
        return this.cursor;
        str = this.sql + " " + this.max;
      }
    }
    catch (android.database.SQLException localSQLException)
    {
      throw SqlExceptionUtil.create("Problems executing Android query: " + (String)localObject, localSQLException);
    }
  }

  public int runExecute()
    throws java.sql.SQLException
  {
    if (!this.type.isOkForExecute())
      throw new IllegalArgumentException("Cannot call execute on a " + this.type + " statement");
    return execSql(this.db, "runExecute", this.sql, getArgArray());
  }

  public DatabaseResults runQuery(ObjectCache paramObjectCache)
    throws java.sql.SQLException
  {
    if (!this.type.isOkForQuery())
      throw new IllegalArgumentException("Cannot call query on a " + this.type + " statement");
    return new AndroidDatabaseResults(getCursor(), paramObjectCache);
  }

  public int runUpdate()
    throws java.sql.SQLException
  {
    if (!this.type.isOkForUpdate())
      throw new IllegalArgumentException("Cannot call update on a " + this.type + " statement");
    if (this.max == null);
    for (String str = this.sql; ; str = this.sql + " " + this.max)
      return execSql(this.db, "runUpdate", str, getArgArray());
  }

  public void setMaxRows(int paramInt)
    throws java.sql.SQLException
  {
    isInPrep();
    this.max = Integer.valueOf(paramInt);
  }

  public void setObject(int paramInt, Object paramObject, SqlType paramSqlType)
    throws java.sql.SQLException
  {
    isInPrep();
    if (this.args == null)
      this.args = new ArrayList();
    if (paramObject == null)
    {
      this.args.add(paramInt, null);
      return;
    }
    switch (1.$SwitchMap$com$j256$ormlite$field$SqlType[paramSqlType.ordinal()])
    {
    default:
      throw new java.sql.SQLException("Unknown sql argument type: " + paramSqlType);
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
    case 8:
    case 9:
    case 10:
    case 11:
      this.args.add(paramInt, paramObject.toString());
      return;
    case 12:
    case 13:
      this.args.add(paramInt, paramObject);
      return;
    case 14:
    case 15:
    }
    throw new java.sql.SQLException("Invalid Android type: " + paramSqlType);
  }

  public void setQueryTimeout(long paramLong)
  {
  }

  public String toString()
  {
    return getClass().getSimpleName() + "@" + Integer.toHexString(super.hashCode());
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.j256.ormlite.android.AndroidCompiledStatement
 * JD-Core Version:    0.6.2
 */